const express = require('express');
const app = express();
const tools = require('./utils');
const UniversalVideoParser = require('./UniversalVideoParser')
const parser = new UniversalVideoParser();
const { extractUrl } = tools;
app.get('/api/download', async (req, res) => {
  const { url } = req.query;
  if (!url) {
    return res.status(400).json({ message: '缺少参数', code: 400 });
  }
  const downloadUrl = extractUrl(decodeURIComponent(url));
  const result = await parser.parseVideo(downloadUrl, {
    useThirdParty: true,
    useSelfParse: true,
    timeout: 20000
  })
  res.status(200).json({ code: 200, message: 'success', data: { videoUrl: result.url } })
})




app.listen(3000, () => {
  console.log('localhost:3000');
});